﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Text.Tagging;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Text;
using LuaLanguageExtension.Parsing;
using Microsoft.VisualStudio.Text.Classification;

namespace LuaLanguageExtension.Tags
{
    /// <summary>
    /// Provides tags for text buffrers
    /// </summary>
    /// <remarks> Imports parser object in order to generate tokenizer for tagger</remarks>
    [Export(typeof(ITaggerProvider))]
    [ContentType(Constants.LuaLanguageExtension)]
    [TagType(typeof(ClassificationTag))]
    class TaggerProvider : ITaggerProvider
    {
        [Export]
        [Name(Constants.LuaLanguageExtension)]
        [BaseDefinition("code")]
        internal static ContentTypeDefinition LuaContentType = null;

        [Export]
        [FileExtension(".lua")]
        [ContentType(Constants.LuaLanguageExtension)]
        internal static FileExtensionToContentTypeDefinition LuaFileType = null;


        [Import]
        internal IObjectModelProviderBroker tokenStreamProviderBroker { get; set; }

        [Import]
        internal IClassificationTypeRegistryService ClassificationTypeRegistry = null;


        public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
        {
            if (tokenStreamProviderBroker.IsLua(buffer)) return new Tagger(tokenStreamProviderBroker, buffer, this.ClassificationTypeRegistry) as ITagger<T>;
            else return null;
        }

    }
}
